<template>
	<view class="start" :style="{width: screenWidth + 'px', height:screenHeight + 'px' }" v-if="openPicture">
		<!-- <image class="image" src="/static/start.png" mode="aspectFill" :style="{width: screenWidth + 'px', height:screenHeight + 'px' }"></image> -->
		<!-- 		<image class="image" src="/static/start1.png" mode="aspectFill"
			:style="{width: screenWidth + 'px', height:screenHeight + 'px' }"></image> -->
		<!-- <image v-if="flag" class="image" src="/static/icon3/start-n/1080_1920.png" mode="aspectFill"
			:style="{width: screenWidth + 'px', height:screenHeight + 'px' }"></image>
		<image v-if="!flag" class="image" src="/static/icon3/start-n/2_1080_1920.png" mode="aspectFill"
			:style="{width: screenWidth + 'px', height:screenHeight + 'px' }"></image> -->
		<image class="image" :src="openPicture" mode="aspectFill"
			:style="{width: screenWidth + 'px', height:screenHeight + 'px' }"></image>
		<!-- 		<view class="top">
			<image class="image2" src="/static/logo2.png" mode="aspectFill"></image>
			<text class="text1">招工 找工 就上找零工</text>
		</view> -->
		<!-- 		<view class="bottom">
			<text class="text2">找零工APP</text>
			<text class="text3">©2020 找零工 ALL rights.reserved</text>
		</view> -->
		<text class="clickTo" @click="goToIndex">点击跳转{{countDown}}</text>
		<!-- <view v-if="isShow" class="mask">
			<agreement></agreement>
		</view> -->
	</view>
</template>
<script>
	import agreement from './agreement.vue'
	export default {
		components: {
			agreement,
		},
		data() {
			return {
				screenWidth: 0,
				screenHeight: 0,
				countDown: 3,
				isShow: false,
				flag: false,
				openPicture: '',
				timer: ''
			}
		},
		onLoad() {
			console.log('s load');
			this.getFlag()
			// plus.navigator.setFullscreen(true); 
			// 获取系统信息
			this.initSystemInfo();
			// 获取开屏页
			this.openImg();
		},
		onShow() {
			console.log('s show');
			// if (!uni.getStorageSync('first-is')) {
			// 	this.isShow = true
			// 	//this.handleCountDown()
			// } else {
			// 	// 倒计时
			// 	this.handleCountDown()
			// }
			this.handleCountDown()
		},
		methods: {
			// 获取开屏页
			async openImg() {
				let c = new Date().getDate()
				if (uni.getStorageSync('getOpenImgTime')) {
					if (c == uni.getStorageSync('getOpenImgTime')) {
						this.openPicture = uni.getStorageSync('openImg')
					} else {
						let res = await this.$fetch(this.$api.openImg, {}, 'GET')
						if (res.code) return uni.showToast({
							title: res.msg,
							icon: 'none'
						})
						this.openPicture = res.data ? res.data.url : null
						uni.setStorageSync('openImg', this.openPicture)
					}
				} else {
					let res = await this.$fetch(this.$api.openImg, {}, 'GET')
					if (res.code) return uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					this.openPicture = res.data ? res.data.url : null
					uni.setStorageSync('openImg', this.openPicture)
				}
				uni.setStorageSync('getOpenImgTime', c)
				if (!this.openPicture) {
					this.flag = false
					console.log('啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊啊')
					this.goToIndex();
				}
			},
			// 获取系统信息
			initSystemInfo() {
				// #ifdef APP-PLUS
				if (!uni.getStorageSync('channel')) {
					//渠道  "douying","baidu","xiaomi","pingguo","yingyongbao","360","huawei","oppo","vivo","jvliang","qita"
					const plat = uni.getSystemInfoSync().platform
					if (plat == "ios") {
						uni.setStorageSync("channel", "pingguo")
					} else if (plat == "android") {
						uni.setStorageSync("channel", plus.runtime.channel) //渠道标识
					}
					// uni.setStorageSync("channel", "huawei")
					// uni.setStorageSync("channel", "qita")
					// uni.setStorageSync("channel", "vivo")
				}
				// #endif
				uni.setStorageSync("version", "2.5.3") //版本标识
				uni.getSystemInfo({
					success: (res) => {
						this.screenWidth = res.screenWidth
						this.screenHeight = res.screenHeight
					}
				})
			},
			// 倒计时
			// handleCountDown() {
			// 	this.timer = setInterval(() => {
			// 		this.countDown -= 1;
			// 		// console.log(this.countDown);
			// 		if (this.countDown <= 0) {
			// 			this.countDown = 0;
			// 			clearInterval(this.timer);
			// 			this.timer = null;
			// 			this.goToIndex();
			// 		}
			// 	}, 1000);
			// },
			handleCountDown() {
				let timer = setInterval(() => {
					this.countDown -= 1;
					// console.log(this.countDown);
					if (this.countDown <= 0) {
						this.countDown = 0;
						clearInterval(timer);
						timer = null;
						this.goToIndex();
					}
				}, 1000);
			},
			// 跳转
			// goToIndex() {
			// 	// plus.navigator.setFullscreen(false); 
			// 	clearInterval(this.timer);
			// 	this.timer = null;
			// 	this.countDown = 0;
			// 	uni.reLaunch({
			// 		url: '/pages/index/index'
			// 	});
			// },
			goToIndex() {
				this.countDown = 0
				// plus.navigator.setFullscreen(false); 
				uni.switchTab({
					url: '/pages/index/index'
				});
			},
			getFlag() {
				let myDate = new Date();
				let day = myDate.getDate();
				this.flag = day % 2 == 0
			},
		}
	}
</script>
<style>
	.start {
		position: relative;
		flex-direction: column;
		align-items: center;
		justify-content: space-between;
		background-color: #FCC928;
		/* background-color: #D60A07; */
		width: 750rpx;
		height: 100vh;
	}

	.image {
		z-index: 1;
		position: absolute;
		top: 0;
		left: 0;
		width: 750rpx;
		height: 100vh;
	}

	.top {
		align-items: center;
	}

	.image2 {
		z-index: 10;
		margin-top: 296rpx;
		margin-bottom: 30rpx;
		width: 206rpx;
		height: 206rpx;
	}

	.text1 {
		z-index: 10;
		font-family: PingFangSC-Semibold;
		font-size: 22px;
		color: #402110;
	}

	.bottom {
		z-index: 10;
		align-items: center;
	}

	.text2 {
		z-index: 10;
		font-family: PingFangSC-Semibold;
		font-weight: bold;
		font-size: 22px;
		color: #402110;
		margin-bottom: 30rpx;
	}

	.text3 {
		z-index: 10;
		font-family: PingFangSC-Regular;
		font-size: 17px;
		color: #402110;
		margin-bottom: 60rpx;
	}

	.clickTo {
		position: fixed;
		right: 40rpx;
		top: 90rpx;
		color: #FFFFFF;
		border-width: 2rpx;
		border-style: solid;
		border-color: #FFFFFF;
		background-color: rgba(0, 0, 0, 0.5);
		border-radius: 30rpx;
		font-size: 14px;
		padding-top: 5rpx;
		padding-bottom: 5rpx;
		padding-left: 25rpx;
		padding-right: 25rpx;
		z-index: 99;
	}

	.mask {
		z-index: 999;
		width: 750rpx;
		top: 0;
		bottom: 0;
		left: 0;
		right: 0;
		position: fixed;
		background-color: rgba(0, 0, 0, 0.5);
		justify-content: center;
		align-items: center;
	}
</style>